package com.ymatou.iapi.withdraw.testcase;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.withdraw.parameter.ExportWithDrawInvoiceBean;
import com.ymatou.iapi.withdraw.parameter.PassApprovalBean;
import com.ymatou.iapi.withdraw.parameter.applyBankWithDrawForSellerBean;
import com.ymatou.iapi.withdraw.service.ExportWithDrawInvoiceCall;
import com.ymatou.iapi.withdraw.service.PassApprovalCall;
import com.ymatou.iapi.withdraw.service.applyBankWithDrawForSellerCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoice;
import com.ymttest.database.sqlwapper.WithdrawWapper;
import com.ymttest.utils.TestDataManager;
/**
*导出--买家/买手提现单线下打款
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ExportWithDrawInvoice{
	private static ExportWithDrawInvoiceBean ebean;
	private static ExportWithDrawInvoiceCall ecall;
	private final int sellerid=3383;
	private final String sellerName="wesper";
	
	private final int userId=4085;
	private final String userName="lunchzhao";

	private final String fundAccountId_sellerId="925CF663-FCBA-4380-846B-32162E58C345";
	private final String fundAccountName_sellerId="吴文";
	private final String fundAccountNo_sellerId="123456789123";
	
	private final String fundAccountId_buer="925CF663-FCBA-4380-846B-32162E58C317";
	private final String fundAccountName_buer="吴文买家";
	private final String fundAccountNo_buer="987654321789";
	
	private final String abroadFundAccountId="a0d8378e-af28-45bc-b211-5304d4869829";
	private final String abroadFundAccountName="wuwen";
	private final String abroadFundAccountNo="123456789123456";
	
	private final String alipayAccountNo_seller="18621614678";
	private final String alipayAccountName_seller="wuwenseller";
	private final String alipayAccountName_Id_seller="9d53eb3a-5867-4334-9735-269156eb7a26";
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("导出--买家/买手提现单线下打款");
	}

	@Before
	public void caseUp() {
		ebean=new ExportWithDrawInvoiceBean();
		ecall=new ExportWithDrawInvoiceCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(ecall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
//	private void check_WithDrawInvoice() throws InterruptedException
//	{
//		//1:Ymt_WithDrawInvoice 提现申请信息主表
//		Date da = new Date(System.currentTimeMillis());
//	    Calendar now = Calendar.getInstance();
//	    now.setTime(da);
//	    
//	    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
//	    String date=simpleDateFormat.format(new Date());
//	    String y=date.substring(0,4);
//	    String m=date.substring(4,6);
//	    String d=date.substring(6,8);
//	    
//	    ecall.getWithDrawInvoiceListResp();
//	    
//		Logger.comment("1:验证数据表 Ymt_WithDrawInvoice 提现申请信息主表");
//		ymtinvoive.createCriteria().andWithDrawInvoiceIdEqualTo(invoiceId);
//		List<Ymt_WithDrawInvoice> invoivelist = WithdrawWapper.selectYmtWithDrawInvoice(ymtinvoive);
//		Logger.verifyEquals(1, invoivelist.size(), "验证申请单据表有数据");
//		Logger.verifyEquals(invoiceId.substring(0, 11), "FTX"+y+m+d, "验证申请单据是否正确");
//		if(invoivelist.size()>0)
//		{
//			Ymt_WithDrawInvoice invoive=invoivelist.get(0);
//			Logger.verifyEquals(bean.getUserType(), invoive.getUserAccountType(), "验证Ymt_WithDrawInvoice数据库中 UserAccountType字段与传入的一致");
//			Logger.verifyEquals(bean.getWithDrawAmount().stripTrailingZeros().toPlainString(), invoive.getWithDrawAmount().stripTrailingZeros().toPlainString(), "验证Ymt_WithDrawInvoice数据库中 WithDrawAmount字段与传入的一致");
//			//-2,"待提交"  -1,"失效"  0,"待处理"  1,"处理中"  2,"处理失败"  3,"已完成"
//			Logger.verifyEquals(0, invoive.getInvoiceStatus(), "验证Ymt_WithDrawInvoice数据库中 InvoiceStatus=0 待处理");
//			Logger.verifyEquals(bean.getUserId(), invoive.getUserId(), "验证Ymt_WithDrawInvoice数据库中 UserId字段与传入的一致");
//			Logger.verifyEquals(bean.getApplyLoginId(), invoive.getUserLoginId(), "验证Ymt_WithDrawInvoice数据库中 ApplyLoginId字段与传入的一致");
//			//1:人名币提人名币 2:人名币提澳元 3:人名币提日元 4:人名币提美元 5:人名币提欧元 6:人名币提英镑 7:人名币提加拿大元 8:人名币提韩元
//			Logger.verifyEquals(0, invoive.getWithDrawType(), "验证Ymt_WithDrawInvoice数据库中 WithDrawType字段与传入的一致");
//			
//			Logger.verifyEquals(true, invoive.getWithDrawTime().toString().length()>0, "验证Ymt_WithDrawInvoice数据库中 WithDrawTime");
//			
//			//0,"银行" 1,"第三方"  2,"贝海" 3,"B2B"
//			Logger.verifyEquals(1, invoive.getReceivableAccountType(), "验证Ymt_WithDrawInvoice数据库中 ReceivableAccountType字段与传入的一致");
//			//第三方支付平台账号 如用户使用支付宝或者贝宝进行收款，则此字段为第三方支付平台账号
//			Logger.verifyEquals(bean.getAlipayAccountNo(), invoive.getThirdPartyPlatformAccount(), "验证Ymt_WithDrawInvoice数据库中 ThirdPartyPlatformAccount字段与传入的一致");
//
//			Logger.verifyEquals(true, invoive.getApplyTime().toString().length()>0, "验证Ymt_WithDrawInvoice数据库中ApplyTime");
//			Logger.verifyEquals(1, invoive.getCurrencyType(), "验证Ymt_WithDrawInvoice数据库中 CurrencyType字段与传入的一致");
//			Logger.verifyEquals(bean.getAlipayAccountName(), invoive.getBankAccountName(), "验证Ymt_WithDrawInvoice数据库中 BankAccountName字段与传入的一致");
//			//Logger.verifyEquals("支付宝", invoive.getBankName(), "验证Ymt_WithDrawInvoice数据库中 BankName字段与传入的一致");
//			//0:等待客服审批  1:等待客服审批客服审批拒绝 2:客服审批通过 3:财务审批拒绝 4:财务审批通过 5:拒绝支付 6:同意支付
//			//第三方提现需要客服审批，提现到贝海客服自动审核
//			Logger.verifyEquals(0, invoive.getApproveStatus(), "验证Ymt_WithDrawInvoice数据库中 ApproveStatus字段与传入的一致");
//			
//			Logger.verifyEquals(true, invoive.getCreateTime().toString().length()>0, "验证Ymt_WithDrawInvoice数据库中CreateTime");
//			Logger.verifyEquals(true, invoive.getUpdateTime().toString().length()>0, "验证Ymt_WithDrawInvoice数据库中UpdateTime");
//			Logger.verifyEquals(bean.getRemark(), invoive.getRemark(), "验证Ymt_WithDrawInvoice数据库中Remark");
//			//1,"买家PC" 2,"买手PC"  3,"运营后台" 4,"买家App" 5,"买手App" 6,"保证金提现" 7,"码头提现到贝海" 8,"专项保证金" 9,"b2b"
//			if(bean.getUserType()==0)
//			   Logger.verifyEquals(1, invoive.getWithDrawChannel(), "验证Ymt_WithDrawInvoice数据库中WithDrawChannel");
//			else if(bean.getUserType()==1)
//			   Logger.verifyEquals(2, invoive.getWithDrawChannel(), "验证Ymt_WithDrawInvoice数据库中WithDrawChannel");
//			//-1:作废  0:申请提现  1:提现取消  2:提现拒绝  3:提现成功  4:提现失败
//			Logger.verifyEquals(0, invoive.getWithDrawBusinessScene(), "验证Ymt_WithDrawInvoice数据库中WithDrawBusinessScene");
//			String businessName=check_AccountType();
//			Logger.verifyEquals(businessName, invoive.getBusinessName(), "验证Ymt_WithDrawInvoice数据库中BusinessName");
//			Logger.verifyEquals(bean.getAccountTypeId(), invoive.getAccountType(), "验证Ymt_WithDrawInvoice数据库中AccountType");
//		}
//	}
		
	/**
	 * 买手申请到银行卡
	 * @param userId 买家/买手
	 * @throws Exception
	 */
	private  String applyBankForseller() throws Exception {
		
		applyBankWithDrawForSellerBean sellerBean=new applyBankWithDrawForSellerBean();
		applyBankWithDrawForSellerCall sellerCall=new applyBankWithDrawForSellerCall();
		WithdrawWapper WithdrawWapper=new WithdrawWapper();
		
		//给帐号充值
		String accountid = AccountCallServiceV2.getAccountId(sellerid, 1);
		AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999999),
				new BigDecimal(0));
		//冻结资金
		BigDecimal freeze= WithdrawWapper.getSumFreezebyUserId(sellerid);
		Logger.comment("################冻结资金："+freeze);
		//查看账户余额
		BigDecimal balance=AccountCallServiceV2.getAccountBalance(sellerid, 1);
		Logger.comment("################账户余额："+balance);
		
		sellerBean.setUserId(sellerid);
		sellerBean.setWithDrawChannel(1);
		sellerBean.setAccountTypeId(1);//提现帐户类型Id，默认值:1.人民币余额帐户
	    sellerBean.setWithDrawAmount(new BigDecimal(1000));
	    sellerBean.setBusinessNo(new TestDataManager().getRandomNum(8));
        sellerBean.setRemark("测试提现到国际银行卡");
        sellerBean.setApplyUserId(sellerid);
        sellerBean.setApplyLoginId(sellerName);
        
        sellerBean.setBankAccountName(abroadFundAccountName);
        sellerBean.setBankAccountNo(abroadFundAccountNo);
        sellerBean.setFundAccountId(abroadFundAccountId);
	    sellerBean.setCurrencyType(1);//4 美元 	 1 人名币
        sellerBean.setIdempotentNo(new TestDataManager().getRandomNum(8));
        
        sellerCall.setData(sellerBean);
        sellerCall.callService();	
		return sellerCall.getInvoiceId();

	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_001() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款");
		try {
			PassApprovalBean bean=new PassApprovalBean();
			PassApprovalCall call=new PassApprovalCall();
			
			String invoiceId=applyBankForseller();
			//一级审核
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核通过_"+TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			//二级审核
			bean.setApprovalLevel(2);
			bean.setApprovalResult("二级审核通过_"+TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			//三级审核
			bean.setApprovalLevel(3);
			bean.setApprovalResult("三级审核通过_"+TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
		//	bean.setAccountType(1);
			
			ebean.setOperator("操作人_"+TestDataManager.getRandomIntNum(5));
			ebean.setOperatorId(TestDataManager.getRandomIntNum(5));
			ebean.setIsPaidSuccess(false);
			
			ecall.setData(ebean);
			ecall.callService();			
			//验证
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_001_1() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-导入两次，第二次导入失败，返回为空");
		try {
			PassApprovalBean bean=new PassApprovalBean();
			PassApprovalCall call=new PassApprovalCall();
			
			String invoiceId=applyBankForseller();
			//一级审核
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核通过_"+TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			//二级审核
			bean.setApprovalLevel(2);
			bean.setApprovalResult("二级审核通过_"+TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			//三级审核
			bean.setApprovalLevel(3);
			bean.setApprovalResult("三级审核通过_"+TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
		//	bean.setAccountType(1);
			ebean.setOperator("操作人_"+TestDataManager.getRandomIntNum(5));
			ebean.setOperatorId(TestDataManager.getRandomIntNum(5));
			ecall.setData(ebean);
			ecall.callService();
			ecall.callService();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_002() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-withDrawInvoiceId提现单号不为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_003() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-accountType账户类型不为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_004() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-approveStatus审核状态不为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_005() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-isPaidSuccess是否支付成功不为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_006() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-applyUserLoginId申请人不为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_007() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-receivableAccountType收款账户类型不为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_008() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-sellerLevelList买手等级列表不为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_009() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-withdrawAccountType提现账户内部用账户类型不为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_010() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-withDrawType=0人民币TO人民币");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_011() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-withDrawType=1人民币提美元");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_012() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-operator操作者为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExportWithDrawInvoice_013() {
		Logger.start(true,"正例-导出--买家/买手提现单线下打款-operatorId操作者id为空");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			ecall.setData(ebean);
			ecall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}